package com.homework;

import java.util.Scanner;

public class Calculator{
        public static void main(String[] args) {
            Scanner sc =new Scanner(System.in);
            Calculator calculator = new Calculator();

            Scanner scanner = new Scanner(System.in);
            System.out.println("请输入第一个数据");
            double a=scanner.nextDouble();

            System.out.println("请输入运算符：");
            String operator=scanner.next();

            System.out.println("请输入第二个数据");
            double b= scanner.nextDouble();

            double result=0;//存储最后的计算结果
            scanner.close();//关闭scanner资源

            // 根据输入的运算符调用不同的方法
            if ("+".equals(operator)){//equals判断字符是否相等
                result= calculator.add(a,b);
            }//调用减法
            else if ("-".equals(operator)){
                result=calculator.sub(a,b);
            }
            else if ("*".equals(operator)){
                result=calculator.multiply(a,b);
            }
            else if ("/".equals(operator)){
                result=calculator.div(a,b);
            }
            System.out.println("最终结果为"+result);

        }
        public double add(double a,double b){
            return a+b;
        }
        public double sub(double a,double b){
            return a-b;
        }
        public double multiply(double a, double b){
            return a*b;
        }
        public double div(double a, double b){
            return a/b;
        }
    }
